using System.ComponentModel.DataAnnotations;

namespace CoreManager.Models.DTOs
{
    /// <summary>
    /// 用户响应DTO
    /// </summary>
    public class UserDto
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; } = string.Empty;

        /// <summary>
        /// 真实姓名
        /// </summary>
        public string? RealName { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        public string? Email { get; set; }

        /// <summary>
        /// 手机号
        /// </summary>
        public string? Phone { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string? Avatar { get; set; }

        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 最后登录时间
        /// </summary>
        public string? LastLoginTime { get; set; }

        /// <summary>
        /// 最后登录IP
        /// </summary>
        public string? LastLoginIp { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime { get; set; } = string.Empty;

        /// <summary>
        /// 更新时间
        /// </summary>
        public string? UpdateTime { get; set; }

        /// <summary>
        /// 用户角色ID列表
        /// </summary>
        public List<int> RoleIds { get; set; } = new List<int>();

        /// <summary>
        /// 用户角色列表
        /// </summary>
        public List<RoleDto> Roles { get; set; } = new List<RoleDto>();
    }

    /// <summary>
    /// 用户查询DTO
    /// </summary>
    public class UserQueryDto
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 页大小
        /// </summary>
        public int PageSize { get; set; } = 20;

        /// <summary>
        /// 用户名
        /// </summary>
        public string? UserName { get; set; }

        /// <summary>
        /// 真实姓名
        /// </summary>
        public string? RealName { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        public string? Email { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public int? Status { get; set; }
    }

    /// <summary>
    /// 创建用户DTO
    /// </summary>
    public class CreateUserDto
    {
        /// <summary>
        /// 用户名
        /// </summary>
        [Required(ErrorMessage = "用户名不能为空")]
        public string UserName { get; set; } = string.Empty;

        /// <summary>
        /// 密码
        /// </summary>
        [Required(ErrorMessage = "密码不能为空")]
        [MinLength(6, ErrorMessage = "密码长度不能少于6位")]
        public string Password { get; set; } = string.Empty;

        /// <summary>
        /// 真实姓名
        /// </summary>
        public string? RealName { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [EmailAddress(ErrorMessage = "邮箱格式不正确")]
        public string? Email { get; set; }

        /// <summary>
        /// 手机号
        /// </summary>
        public string? Phone { get; set; }

        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        public int Status { get; set; } = 1;

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }

        /// <summary>
        /// 角色ID列表
        /// </summary>
        public List<int> RoleIds { get; set; } = new List<int>();
    }

    /// <summary>
    /// 更新用户DTO
    /// </summary>
    public class UpdateUserDto
    {
        /// <summary>
        /// 真实姓名
        /// </summary>
        public string? RealName { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [EmailAddress(ErrorMessage = "邮箱格式不正确")]
        public string? Email { get; set; }

        /// <summary>
        /// 手机号
        /// </summary>
        public string? Phone { get; set; }

        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }

        /// <summary>
        /// 角色ID列表
        /// </summary>
        public List<int> RoleIds { get; set; } = new List<int>();
    }

    /// <summary>
    /// 用户角色分配DTO
    /// </summary>
    public class AssignUserRolesDto
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        [Required(ErrorMessage = "用户ID不能为空")]
        public int UserId { get; set; }

        /// <summary>
        /// 角色ID列表
        /// </summary>
        public List<int> RoleIds { get; set; } = new List<int>();
    }

    /// <summary>
    /// 批量删除请求DTO
    /// </summary>
    public class BatchDeleteRequest
    {
        /// <summary>
        /// 用户ID列表
        /// </summary>
        [Required(ErrorMessage = "请选择要删除的用户")]
        public List<int> Ids { get; set; } = new();
    }

    /// <summary>
    /// 重置密码请求DTO
    /// </summary>
    public class ResetPasswordRequest
    {
        /// <summary>
        /// 新密码
        /// </summary>
        [Required(ErrorMessage = "新密码不能为空")]
        [MinLength(6, ErrorMessage = "密码长度不能少于6位")]
        public string NewPassword { get; set; } = string.Empty;
    }

    /// <summary>
    /// 状态切换请求DTO
    /// </summary>
    public class ToggleStatusRequest
    {
        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        [Range(0, 1, ErrorMessage = "状态值只能是0或1")]
        public int Status { get; set; }
    }
}